<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="反馈类型" prop="reactionType">
        <el-select
          v-model="queryParams.reactionType"
          placeholder="请选择反馈类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in reactionTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="内容类型" prop="contentType">
        <el-select
          v-model="queryParams.contentType"
          placeholder="请选择内容类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in contentTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否公布" prop="isPublish">
        <el-select
          v-model="queryParams.isPublish"
          placeholder="请选择类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in isPublishOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发布昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入发布人昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="响应状态" prop="reactionState">
        <el-select
          v-model="queryParams.reactionState"
          placeholder="请选择状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in reactionStateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发布类型" prop="reactionState">
        <el-select
          v-model="queryParams.sendType"
          placeholder="请选择类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in sendOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="社区名称" prop="reactionState">
        <el-select
          v-model="queryParams.communityId"
          placeholder="请选择社区网格"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in communityList"
            :key="dict.id"
            :label="dict.areaName"
            :value="parseInt(dict.id)"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['interest:reaction:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['interest:reaction:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['interest:reaction:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['interest:reaction:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-card>
      <el-scrollbar style="height:100%; width:100%;">
        <el-row style="height:100%; width:2080px;">
          <el-table
            v-loading="loading"
            :data="reactionList"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="主键" align="center" prop="id" />
            <el-table-column
              label="反馈类型"
              align="center"
              prop="reactionType"
              :formatter="reactionTypeFormat"
            />
            <el-table-column
              label="内容类型"
              align="center"
              prop="contentType"
              :formatter="contentTypeFormat"
            />
            <el-table-column
              label="是否公布"
              align="center"
              prop="isPublish"
              :formatter="isPublishFormat"
            />
            <el-table-column
              label="发布类型"
              align="center"
              prop="sendType"
              :formatter="sendFormat"
            />
            <el-table-column label="头像" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <img :src="scope.row.avatar" alt="" style="width: 50px;height: 50px; border-radius: 50px">
              </template>
            </el-table-column>
            <el-table-column label="发布人" align="center" prop="nickName" />
            <el-table-column
              label="响应状态"
              align="center"
              prop="reactionState"
              :formatter="reactionStateFormat"
            />
            <el-table-column label="点赞数" align="center" prop="greatNum" />
            <el-table-column label="网格名称" align="center" prop="communityAreaName" />
            <el-table-column label="网格处理人" align="center" prop="communityAreaPerson" />
            <el-table-column label="组别处理人" align="center" prop="groupAreaPerson" />
            <el-table-column label="点赞数" align="center" prop="greatNum" />
            <!-- <el-table-column label="反应地点" align="center" prop="address"/> -->
            <el-table-column label="图片" align="center" class-name="small-padding fixed-width" >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  @click="ImagePreview(scope.row)"
                  v-hasPermi="['interest:reaction:edit']"
                >图片预览</el-button
                >
              </template>
            </el-table-column>
            <!-- <el-table-column label="经度" align="center" prop="longitude" />
            <el-table-column label="纬度" align="center" prop="latitude" /> -->
            <el-table-column label="用户评论" align="center" prop="contentType" :formatter="contentTypeFormat" >
              <template slot-scope="scope">
                <router-link :to="'/interest/reaction-discuss/index/' + scope.row.reauserId" class="link-type">
                  <span>查看评论</span>
                </router-link>
              </template>
            </el-table-column>

            <el-table-column label="政务反馈" align="center" prop="contentType" :formatter="contentTypeFormat" >
              <template slot-scope="scope">
                <router-link :to="'/interest/reaction-back/index/' + scope.row.id" class="link-type">
                  <span>处理反馈</span>      </router-link>
              </template>
            </el-table-column>

            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['interest:reaction:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['interest:reaction:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-row> 
      </el-scrollbar>
    </el-card>
   
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改反馈信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="反馈类型" prop="reactionType">
              <el-select
                v-model="form.reactionType"
                placeholder="请选择反馈类型"
              >
                <el-option
                  v-for="dict in reactionTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事件类型" prop="contentType">
              <el-select
                v-model="form.contentType"
                placeholder="请选择事件类型"
              >
                <el-option
                  v-for="dict in contentTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="反馈内容" prop="content">
          <el-input
            v-model="form.content"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-row>
          <el-col :span="12">
          <el-form-item label="是否公布">
            <el-radio-group v-model="form.isPublish">
              <el-radio
                v-for="item in isPublishOptions"
                :key="item.dictValue"
                :label="parseInt(item.dictValue)"
              >{{item.dictLabel}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发布人" prop="userId">
              <el-select
                v-model="form.userId"
                placeholder="请选择发布人"
                :disabled="opendis"
                filterable
                clearable
              >
                <el-option
                  v-for="dict in userOptions"
                  :key="dict.userId"
                  :label="dict.nickName"
                  :value="parseInt(dict.userId)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
         <el-form-item label="响应状态">
            <el-radio-group v-model="form.reactionState">
              <el-radio
                v-for="item in reactionStateOptions"
                :key="item.dictValue"
                :label="parseInt(item.dictValue)"
              >{{item.dictLabel}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        <el-form-item label="反馈地点" prop="address">
          <el-input
            v-model="form.address"
            type="textarea"
            placeholder="请输入内容"
            @blur="queryPoint()"
          />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="经度" prop="longitude">
              <el-input v-model="form.longitude" placeholder="请输入经度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度" prop="latitude">
              <el-input v-model="form.latitude" placeholder="请输入纬度" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="社区名称" prop="communityId">
          <el-select v-model="form.communityId" placeholder="请选择社区网格" filterable clearable>
            <el-option
              v-for="dict in communityList"
              :key="dict.id"
              :label="dict.areaName"
              :value="parseInt(dict.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上传图片">
          <imageUpload v-model="form.imgUrl" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

<!-- 图片预览-->
    <el-dialog :title="title" :visible.sync="imgopen" width="700px" append-to-body>
      <ImagePreview v-model="form.imgUrl" />
    </el-dialog>
  </div>
</template>

<script>
import { listReaction, getReaction, delReaction, addReaction, updateReaction, exportReaction } from "@/api/interest/reaction";
import { getAddressPoint } from "@/api/common/info";
import { getUserList } from "@/api/system/user";
import { getListInfo } from "@/api/basicdata/community";

export default {
  name: "Reaction",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 反馈信息表格数据
      reactionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //图片预览弹出层
      imgopen: false,
      // 禁用用户下拉框选择
      opendis: true,
      // 反馈类型字典
      reactionTypeOptions: [],
      // 内容类型字典
      contentTypeOptions: [],
      // 是否公布字典
      isPublishOptions: [],
      // 响应状态字典
      reactionStateOptions: [],
      // 事件发布类型
      sendOptions: [],
      // 用户信息列表
      userOptions: [],
      // 社区下拉数据
      communityList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reactionType: null,
        contentType: null,
        content: null,
        isPublish: null,
        reauserId: null,
        reactionState: null,
        address: null,
        communityId:null,
        imgUrl: null,
        longitude: null,
        latitude: null,
        nickName: null,
        sendType: null,
        id: null
      },
      // 表单参数
      form: {
        imgUrl: null
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("hxc_reaction_type").then((response) => {
      this.reactionTypeOptions = response.data;
    });
    this.getDicts("hxc_content_type").then((response) => {
      this.contentTypeOptions = response.data;
    });
    this.getDicts("hxc_is_publish").then((response) => {
      this.isPublishOptions = response.data;
    });
    this.getDicts("hxc_reaction_state").then((response) => {
      this.reactionStateOptions = response.data;
    });
    this.getDicts("hxc_send_type").then((response) => {
      this.sendOptions = response.data;
    });
    this.getUser();
    this.getCommunityList();
  },
  methods: {
    /** 获取社区下拉框数据 */
    getCommunityList() {
        getListInfo().then(response => {
            this.communityList = response.data;
        });
    },
    //获取账户信息列表
    getUser() {
      getUserList().then((response) => {
        this.userOptions = response.data;
      });
    },
    /** 查询反馈信息列表 */
    getList() {
      this.loading = true;
      listReaction(this.queryParams).then((response) => {
        this.reactionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //查询经纬坐标
    queryPoint(){
        getAddressPoint(this.from).then(response => {
          this.form.longitude = response.data.lng;
          this.form.latitude = response.data.lat;
        });
    },
    // 反馈类型字典翻译
    reactionTypeFormat(row, column) {
      return this.selectDictLabel(this.reactionTypeOptions, row.reactionType);
    },
    // 内容类型字典翻译
    contentTypeFormat(row, column) {
      return this.selectDictLabel(this.contentTypeOptions, row.contentType);
    },
    // 是否公布字典翻译
    isPublishFormat(row, column) {
      return this.selectDictLabel(this.isPublishOptions, row.isPublish);
    },
    // 响应状态字典翻译
    reactionStateFormat(row, column) {
      return this.selectDictLabel(this.reactionStateOptions, row.reactionState);
    },
    // 响应发布类型字典翻译
    sendFormat(row, column) {
      return this.selectDictLabel(this.sendOptions, row.sendType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        reactionType: null,
        contentType: null,
        content: null,
        isPublish: null,
        reauserId: null,
        reactionState: null,
        address: null,
        imgUrl: null,
        longitude: null,
        latitude: null,
        createTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加反馈信息";
      this.opendis = false;
    },
    /** 图片预览按钮操作 */
    ImagePreview(row) {
      this.reset();
      this.form.imgUrl = row.imgUrl;
      this.imgopen = true;
      this.title = "图片预览";
      this.opendis = false;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.queryParams.id = row.id || this.ids;
      getReaction( this.queryParams).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改反馈信息";
        this.opendis = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateReaction(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReaction(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除反馈信息编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delReaction(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有反馈信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportReaction(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
